package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.Result;
import com.flyduck.system.service.SysDeptService;
import com.flyduck.system.vo.dept.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: flyduck-platform
 * @description: 系统:部门接口
 * @author: flyduck
 * @create: 2021-03-03 20:00
 **/
@Api(tags = "系统:部门接口")
@RestController
@RequestMapping("/system/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @ApiOperation("获取部门树列表")
    @PostMapping("/treeList")
    public Result getDeptTreeList(@RequestBody SysDeptTreeReqVO reqVo){
        List<SysDeptTreeRespVO> deptTreeRespVOS =  sysDeptService.getDeptTreeList(reqVo);
        return Result.success(deptTreeRespVOS);
    }

    @IgnoreAuth
    @ApiOperation("获取部门详情")
    @GetMapping("/detail")
    public Result getDeptDetail(@RequestParam(value = "id",required = true) Long id){
        SysDeptDetailRespVO respVO = sysDeptService.getDeptDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增部门")
    @PostMapping("/add")
    public Result addDept(@RequestBody @Validated SysDeptAddReqVO reqVo){
        boolean flag = sysDeptService.addDept(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑部门")
    @PutMapping("/update")
    public Result updateDept(@RequestBody @Validated SysDeptUpdateReqVO reqVo){
        boolean flag = sysDeptService.updateDept(reqVo);
        return Result.success(flag,"编辑成功");
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/deleye")
    public Result deleteDept(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysDeptService.deleteDept(id);
        return Result.success(flag,"删除成功");
    }

    @IgnoreAuth
    @ApiOperation("获取部门下拉树")
    @GetMapping("/treeSelect")
    public Result getDeptTreeSelect(){
        List<SysDeptTreeSelectRespVO> treeSelect = sysDeptService.getDeptTreeSelect();
        return Result.success(treeSelect);
    }



}
